#include "DomTypeMap.h"

DomTypeMap::DomTypeMap()
{
    // Fill type to string map
    mTypeToStringMap[QDomNode::ElementNode] = "Element";
    mTypeToStringMap[QDomNode::AttributeNode] = "Attribute";
    mTypeToStringMap[QDomNode::TextNode] = "Text";
    mTypeToStringMap[QDomNode::CDATASectionNode] = "CDATASection";
    mTypeToStringMap[QDomNode::EntityReferenceNode] = "EntityReference";
    mTypeToStringMap[QDomNode::EntityNode] = "Entity";
    mTypeToStringMap[QDomNode::ProcessingInstructionNode] = "ProcessingInstruction";
    mTypeToStringMap[QDomNode::CommentNode] = "Comment";
    mTypeToStringMap[QDomNode::DocumentNode] = "Document";
    mTypeToStringMap[QDomNode::DocumentTypeNode] = "DocumentType";
    mTypeToStringMap[QDomNode::DocumentFragmentNode] = "DocumentFragment";
    mTypeToStringMap[QDomNode::NotationNode] = "Notation";
    mTypeToStringMap[QDomNode::BaseNode] = "BaseNode";
    mTypeToStringMap[QDomNode::CharacterDataNode] = "CharacterData";

    // Fill string to type map
    for(int i = 0; i < mTypeToStringMap.size(); i++)
    {
        int key = mTypeToStringMap.keys().at(i);
        mStringToTypeMap[mTypeToStringMap[key]] = key;
    }
}

QString DomTypeMap::nodeTypeToString(int type)
{
    if(mTypeToStringMap.contains(type))
        return mTypeToStringMap[type];
    else
        return QString("Invalid Type");
}

int DomTypeMap::stringToNodeType(QString typeString)
{
    if(mStringToTypeMap.contains(typeString))
        return mStringToTypeMap[typeString];
    else
        return -1;
}
